package com.huluobo.base.net

import android.content.Context
import androidx.room.Room
import com.huluobo.base.db.ParkDatabase
import com.huluobo.base.db.UserDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/**
 *  Created by LC on 2024/8/20.
 */
@Module
@InstallIn(SingletonComponent::class)
object ProviderFactory {
    @Provides
    @Singleton
    fun serviceSign(): ApiServiceLogin = getServiceSign()

    @Provides
    @Singleton
    fun serviceToken(): ApiService = getServiceToken()

    @Provides
    @Singleton
    fun database(@ApplicationContext app: Context): ParkDatabase =
        Room.databaseBuilder(app, ParkDatabase::class.java, "park.db")
            .fallbackToDestructiveMigration()//不需要更新加载策略
            .allowMainThreadQueries().build()

    @Provides
    @Singleton
    fun userDao(database: ParkDatabase): UserDao = database.getUserDao()
}